#ifndef __REALTIMEWAVEFORM_H__
#define __REALTIMEWAVEFORM_H__

#include "allThread.h"

#define WAVEFORM_FIFO_QTY   (9)    /* FIFO个数(和FPGA相关) */
#define WAVEFORM_FIFO_DEPTH (250)  /* FIFO深度(和FPGA相关) */
#define WAVEFORM_GROUP_DEPTH (40000) //一共可以存多少组数据
#define MAX_ERROR_WAVE_GROUP (40)

#define REALTIME_WAVE_SEND_STOP  0
#define REALTIME_WAVE_SEND_START 1

struct oneGroupWaveData{
    uint16_t waveData[WAVEFORM_FIFO_QTY][WAVEFORM_FIFO_DEPTH];
};

struct realtimeGroupWaveData{
    uint32_t currentGroupIndex;
    struct oneGroupWaveData groupWaveData[WAVEFORM_GROUP_DEPTH];
};

typedef struct realtimeWaveDataType_s{
    uint32_t rwdt_sampleDataIndex;  //采样数据点的索引
    uint32_t rwdt_dataIndex;        //数据点的索引
    struct oneGroupWaveData rwdt_oneGroupWaveData;
    struct realtimeGroupWaveData* rwdt_pRealtimeGroupWaveData;
} realtimeWaveDataType_t;

struct realtimeWaveDataSyncInfo{
    uint8_t syncSendFlag;
    uint32_t sendGroupIndex;
    int sendSocketFd;
};

void setRealtimeSyncSendFlag(uint8_t flag);

uint8_t getRealtimeSyncSendFlag(void);

int getRealtimeSyncSendSocketFd(void);

void setRealtimeSyncSendSocketFd(int fd);

uint32_t getCurrentWaveDataGroupIndex(void);

uint32_t getSendGroupIndex(void);

void setSendGroupIndex(uint32_t groupIndex);

void sendGroupIndexIncrement(void);

struct json_object* realtimeGroupWaveDataToJson(uint32_t curGroupIndex);

struct oneGroupWaveData* realtimeGroupWaveDataFromJson(const char* strGroupWaveData);

int errorGroupWaveDataFromJsonObject(struct json_object* errorWaveDataObject);

struct json_object* errorGroupWaveDataToJson(uint32_t curGroupIndex);

int realtimeWaveDataPackageFrame(int fifoIndex, uint32_t curGroupIndex, uint8_t* rsp);

void WaveformSample_Thread(const void* pPara);

#endif
